home *** CD-ROM | disk | FTP | other *** search
/ Language/OS - Multiplatform Resource Library / LANGUAGE OS.iso / lisp / kcl / akcl / akcl1615.lha / lsp / gprof.lsp < prev    next >
Lisp/Scheme  |  1990-08-13  |  4KB  |  133 lines

  1. (in-package 'si)
  2.  
  3. ;;  (load "gprof.o")
  4. ;;  You must have a kcl image with profiling information and monstartup
  5. ;;  typically saved_kcp.   NOTE: if monstartup calls sbrk (true in
  6. ;;  most 4.3bsd's except sun >= OS 4.0)  you must be very careful to
  7. ;;  allocate all the space you will use prior to calling monstartup.
  8. ;;  If subsequent storage allocation causes the hole to move you will
  9. ;;  most certainly lose.  See below for instructions
  10. ;;  on how to construct saved_kcp.
  11.  
  12. ;; If you want function invocation counts to be kept do
  13. ;; (setq compiler::*cc* (concatentate 'string compiler::*cc* " -pg "))
  14. ;; before compiling the relevant files.  (This is done when you load
  15. ;; lsp/gprof.o)
  16.  
  17. ;; In the image saved_kcp Load in your files.  Load in gprof.o: (load
  18. ;; "lsp/gprof.o") Invoke monstartup once to setup buffers: (monstartup
  19. ;; lowpc highpc) eg. (monstartup #x800 3000000) [highpc should be a bit
  20. ;; bigger than the highest address you have seen when loading your files]
  21. ;; Use moncontrol to toggle profiling on and off: (moncontrol 0) to turn
  22. ;; profiling off, and (moncontrol 1) to turn it on.  Use
  23. ;; (wrtie-gmons+syms) to terminate with writing a gmon.out and syms.out
  24. ;; in the current directory.   I know of no way of clearing the buffers,
  25. ;; since secret routines set up the buffers, and we don't know where they
  26. ;; are or how large.  Thus all information is cumulative.
  27.  
  28. ;; % gprof syms.out
  29. ;; will display the output (add -b) to make it briefer.
  30.  
  31. ;; A sample session on rascal:
  32. #|
  33. /usr2/skcl/unixport/saved_kcp
  34. AKCL (Austin Kyoto Common Lisp)  Version(1.147) Sun May 14 15:26:07 CDT 1989
  35. Contains Enhancements by W. Schelter
  36.  
  37. >(load "/tmp/fo")
  38. Loading /tmp/fo.o
  39. start address -T 1d04e0 Finished loading /tmp/fo.o
  40. 528
  41.  
  42. >(load "/usr2/skcl/lsp/gprof")
  43. Loading gprof.o
  44.  
  45.  Adding -pg to the *cc* commandstart address -T 1d0800 
  46. Finished loading gprof.o
  47. 2112
  48.  
  49. ;; NOTE:  If the following calls sbrk [eg 4.3bsd or sun OS3 ] but not Sun OS4,
  50. ;; then you MUST make sure to allocate sufficient memory before doing
  51. ;; monstartup, so that the hole will not have to be moved.   
  52. >(si::monstartup #x800 2000000)
  53. 2584576
  54.  
  55. >(si::goo)(si::goo)                  ;;defined in /tmp/foo.lisp
  56. NIL
  57.  
  58. >NIL
  59.  
  60. >(si::write-gmon+syms)
  61. writing syms..
  62. 0
  63. [NOTE: The safest way to exit the lisp is to stop it with Ctrl-Z
  64. and then kill it.   We do NOT want to run the exit code which
  65. normally writes out a monitoring file].
  66.  
  67. rascal% gprof -b syms.out
  68. ...
  69.                                   called/total       parents 
  70. index  %time    self descendents  called+self    name        index
  71.                                   called/total       children
  72.  
  73.                 0.00        0.00       1/200         _call_or_link [8]
  74.                 0.02        0.02     199/200         GOO [2]
  75. [1]     49.6    0.02        0.02     200         FOO [1]
  76.                 0.02        0.00     200/203         _make_cons [4]
  77.  
  78. ...  Interpretation: Foo is called 199 times by (parent) goo and once
  79. by (parent) call_or_link (the setting up of the fast link).  Foo
  80. itself calls (child) make_cons 200 of the 203 times that make_cons is
  81. called...  Lower down we would see that goo is called twice.
  82.  
  83. -- /tmp/fo.lisp --
  84.  (defun foo () (cons nil nil))
  85.  (defun goo () (sloop::sloop for i below 100 do (foo)))
  86. -- end of file --
  87.  
  88. |#
  89.  
  90. ;;  Creating saved_kcp
  91. ;;  On a sun in sun0S 3 or 4.0
  92. ;;  make gcrt0.o-V
  93. ;;  mkdir akcl/go
  94. ;;  (cd akcl/go ; ln -s ../o/makefile ../o/*.o .)
  95. ;;  remove a few .o files and do
  96. ;;  (cd go ; make  "CFLAGS = -I../h -pg -g -c")
  97.  
  98. ;;  then (cd unixport ; make kcp)
  99.  
  100. (clines
  101.  #-aix3 "#include \"gprof.hc\""
  102.  #+aix3 "#include \"aix_gprof.hc\""
  103.  )
  104.  
  105. (eval-when (load)
  106. (progn (setq compiler::*cc* (CONCATENATE 'string compiler::*cc* " -pg "))
  107.         (format t "~% Adding -pg to the *cc* command"))
  108. )
  109. (defun write-gmon+syms()
  110.   (monitor2 0 0 0 0)
  111.   (princ "writing syms..")
  112.   (set-up-combined)
  113.   (write_outsyms)
  114.   )
  115.  
  116.  
  117. (defentry monstartup (int int) (int "mymonstartup"))
  118.  
  119. (defentry monitor2 (int int int int) (int "mymonitor"))
  120.  
  121. (defentry moncontrol (int) (int "moncontrol"))
  122.  
  123. (defentry write_outsyms () (int "write_outsyms"))
  124.  
  125.  
  126.  
  127.  
  128.  
  129.  
  130.  
  131.  
  132.  
  133.